import redis

import config

from django.core.management import BaseCommand
from sqlhelper import SqlHelper


class Command(BaseCommand):
    help = 'run spider'

    def handle(self, *args, **options):
        self.sql = SqlHelper(db_name = 'autohome_mirror', db_config = config.db_168_3307_config)
        self.redis_db = redis.StrictRedis(**config.redis_config)

        # 64398737
        # 68106271

        for i in range(64398737, 68106271):
            command = 'SELECT forum_id FROM bbs_mirror_6 WHERE forum_id={forum_id} limit 1'.format(forum_id = i)

            result = self.sql.query_one(command, cursor_type = 'dict')
            if result is None or result.get('forum_id', None) is None:
                self.redis_db.sadd('bbs', i)
                print('forum_id:%s' % i)
